let productList = [
  {
    'id': 1,
    'name': '珀莱雅能量面霜檀能因抗皱紧致修护保湿',
    'img': 'imgs/ic_1.png',
    'price': 437
  },
  {
    'id': 2,
    'name': '肌肤之钥CPB超导钻光瓶精华抗老修护紧致',
    'img': 'imgs/ic_2.png',
    'price': 1150
  },
  {
    'id': 3,
    'name': 'SK-II神仙水精华面霜护肤套装礼盒礼物sk2skll',
    'img': 'imgs/ic_3.png',
    'price': 2633
  },
  {
    'id': 4,
    'name': 'AKF散粉定妆粉持久控油不脱妆蜜粉饼',
    'img': 'imgs/ic_4.png',
    'price': 41.6
  },
  {
    'id': 5,
    'name': '雅诗兰黛白金6D黑钻眼霜淡纹淡泪沟抗皱紧致修护舒缓',
    'img': 'imgs/ic_5.png',
    'price': 1300
  },
  {
    'id': 6,
    'name': '欧莱雅第四代小蜜罐面霜水乳套装紧致抗皱护肤品',
    'img': 'imgs/ic_6.png',
    'price': 399
  }
];

// 获取所选商品详细信息
let urlSearchParams = new URLSearchParams(window.location.search);
let productIndex = urlSearchParams.get('index');
let productDetail = productList[productIndex];
productDetail.sku = '套装，净含量50g，退货宝';
let swiperStr = '<img alt="" class="showing" src="' + productDetail.img + '" />';
for (let i = 0; i < 3; i++) {
  swiperStr += '<img alt="" src="imgs/ic_' + ((productDetail.id + i) % 6 + 1) + '.png" />'
}
swiperStr += '<div id="dot" >1/4</div>';
document.getElementById('swiper').innerHTML = swiperStr;
document.getElementById('price').innerHTML = '<span>¥ </span>' + productDetail.price;
document.getElementById('product-name').innerHTML = productDetail.name;

let currentIndex = 0;
let images = document.querySelectorAll('#swiper img');

function showNext() {
  var currentImg = document.querySelector('.showing');
  if (currentImg) {
    currentImg.classList.remove('showing');

    currentIndex += 1;
    if (currentIndex >= images.length) {
      currentIndex = 0;
    }
    var dot = document.querySelector('#dot');
    dot.innerHTML = (currentIndex + 1) + '/4';
    images[currentIndex].classList.add('showing');
  } else {
    images[0].classList.add('showing');
  }
}

setInterval(showNext, 2000);

// 调用应用端函数跳转至商品结算页面
function orderConfirm() {
  arkTSFunObj.jumpOrderConfirm(JSON.stringify(productDetail));
}
